reverse an array in groups of given size